package com.zking.seckillpro.controller;


import com.zking.seckillpro.model.Goods;
import com.zking.seckillpro.model.User;
import com.zking.seckillpro.service.IGoodsService;
import com.zking.seckillpro.service.IRedisService;
import com.zking.seckillpro.util.JsonResponseBody;
import com.zking.seckillpro.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * ��Ʒ��Ϣ�� 前端控制器
 * </p>
 *
 * @author zking
 * @since 2022-03-06
 */
@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IRedisService redisService;
    @Autowired
    private IGoodsService goodsService;
    @RequestMapping("/toGoods")
    public String toGoods(User user,Model model){
//        //判断token是否为空
//        if(null==token)
//            return "redirect:/";
//        //根据token令牌获取session中保存到user对象
//        //User user=(User) session.getAttribute(token);
//        User user = redisService.getUserByToken(token);
//        if(null==user)
//            return "redirect:/";
//        //获取用户对象中的nickname
        model.addAttribute("nickname",user.getNickname());
        return "goods/goodsList";
    }
    @RequestMapping("queryGoodsPager")
    @ResponseBody
    public JsonResponseBody<List<Goods>> queryBooksPager(Goods goods, HttpServletRequest req){

        PageBean pageBean=new PageBean();
        pageBean.setRequest(req);
        return  goodsService.queryGoodsPager(goods,pageBean);
    }
}
